﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TamTreSoSinh.DBContext;

namespace TamTreSoSinh
{
    public partial class ServicePage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadServiceCategory();
        }

        private void LoadServiceCategory()
        {
            DBTamTreEntities dbContext = new DBTamTreEntities();
            List<ServiceCategory> listServiceCategory = dbContext.ServiceCategories.Where(obj => obj.IsVisible).OrderBy(obj => obj.Priority).ToList();
        
            rptServiceCategory.DataSource = listServiceCategory;
            rptServiceCategory.DataBind();
        }

        protected void rptSubService_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            OurService subService = (OurService)e.Item.DataItem;
            HyperLink hpl;
            Label lbl;
            Image img;
            img = (Image)e.Item.FindControl("imgService");
            hpl = (HyperLink)e.Item.FindControl("hplTitle");
            hpl.Text = subService.Title;
            hpl.NavigateUrl = @"ServiceDetailPage.aspx?Id=" + subService.Id;

            lbl = (Label)e.Item.FindControl("lblOverview");
            lbl.Text = subService.Overview;
            img.ImageUrl = subService.MainImage;
        }

        protected void rptServiceCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Repeater rpt = (Repeater)e.Item.FindControl("rptSubService");
            ServiceCategory serviceCategory = (ServiceCategory)e.Item.DataItem;
            HyperLink hpl = (HyperLink)e.Item.FindControl("hplAnchor");
            Label lbl = (Label)e.Item.FindControl("lblServiceTitle");
            lbl.Text = serviceCategory.Title;

            hpl.Attributes.Add("name", "AnchorService" + serviceCategory.Id);

            // Load SubData
            List<OurService> listOurService = serviceCategory.OurServices.OrderBy(obj => obj.Priority).ToList();

            rpt.DataSource = listOurService;
            rpt.DataBind();
        }
    }
}